package com.totoro.tyrank.enums;


import com.totoro.tyrank.constants.ActionConst;
import com.totoro.tyrank.executor.action.ActionExecutor;
import com.totoro.tyrank.executor.action.impl.*;

public enum ActionEnum {
    DELAY_ACTION(ActionConst.DELAY, new DelayActionExecutor()),
    COMMAND_ACTION(ActionConst.COMMAND, new CommandActionExecutor()),
    MESSAGE_ACTION(ActionConst.MESSAGE, new MessageActionExecutor()),
    TITLE_ACTION(ActionConst.TITLE, new TitleActionExecutor()),
    ACTION_BAR_ACTION(ActionConst.ACTION_BAR, new ActionBarActionExecutor()),
    BC_ACTION(ActionConst.BC, new BcActionExecutor());

    private final String actionIdentifier;
    private final ActionExecutor actionExecutor;


    public static ActionEnum getValue(String actionText) {
        ActionEnum[] values = values();
        for (ActionEnum value : values) {
            if (actionText.startsWith(value.actionIdentifier)) {
                return value;
            }
        }
        return null;
    }

    public static ActionExecutor getExecutor(String actionText) {
        ActionEnum actionEnum = getValue(actionText);
        if(null != actionEnum) {
            return actionEnum.actionExecutor;
        }
        return new DefaultActionExecutor();
    }

    ActionEnum(String actionIdentifier, ActionExecutor actionExecutor) {
        this.actionIdentifier = actionIdentifier;
        this.actionExecutor = actionExecutor;
    }
}
